<?php
class ui_circle_default extends ui {
	/**
	 * @param object $S
	 * @param Array $param	= array (
	 * 		
	 * )
	 * @param Array $_GET = array (
	 * 		id				// circle id
	 * 		page
	 * )
	 */
	public function __construct($S, $param) {
		parent::__construct();
		
		if ($this->uid) {
			// Nav
			$S->assign('nav', loadMod('glob/nav/0/0'));
			
			// 参数
			$_GET['id']		= intval($_GET['id']);
			$_GET['page']	= ($_GET['page']>1) ? intval($_GET['page']) : 1;
			$limit 		= 10;
			
			$data_circle = new data_circle();
			$circle = $data_circle->one($this->uid, $_GET['id']);	// 圈子基本信息，圈子访问权限public和member可以访问，
			if ($circle) {
				// 圈子基本信息
				$S->assign('circle', $circle);
				// 圈内成员
				$members = $data_circle->list_member($this->uid, $circle['id'], 1, 100);
				$S->assign('members', $members);
				
				// 文章列表
				$data_save_article = new data_save_article();
				$articles = $data_save_article->ls_in_circle($circle['id'], $_GET['page'], $limit);
				$S->assign('articles', $articles);
				// 判断第一页和最后一页
				$is_last = 0;
				if ($_GET['page'] > 1 and empty($articles)) {					// 不是第一页，而且没有数据了，那么一定就是最后一页了
					$is_last = 1;
					$_GET['page'] = $_GET['page'] - 1;
					$articles = $data_save_article->ls_in_circle($circle['id'], $_GET['page'], $limit);
				}
				$S->assign('is_last', 	$is_last);
				$S->assign('page', 		$_GET['page']);
				$S->assign('articles', 	$articles);

				// 身份
				$member_access = $data_circle->get_access($this->uid, $circle['id']);		// 成员身份 follower/member/admin/founder
				$S->assign('member_access', $member_access);
			}
		} else {
			die2page('http://uread.me');
		}
	}
}
?>